package com.richie696.catalina;

import java.util.ArrayList;
import java.util.List;

public class ServletMapping {

    private String servletName;

    private String servletClass;

    private Servlet servlet;

    private final List<String> urlPatterns = new ArrayList<>(10);

    public String getServletName() {
        return servletName;
    }

    public void setServletName(String servletName) {
        this.servletName = servletName;
    }

    public String getServletClass() {
        return servletClass;
    }

    public void setServletClass(String servletClass) {
        this.servletClass = servletClass;
    }

    public Servlet getServlet() {
        return servlet;
    }

    public void setServlet(Servlet servlet) {
        this.servlet = servlet;
    }

    public List<String> getUrlPatterns() {
        return urlPatterns;
    }

    public void addUrlPattern(String urlPattern) {
        if (urlPattern.startsWith("*")) {
            urlPattern = ".*(" + urlPattern.replaceAll("\\*", ")*(") + ").*";
        } else {
            urlPattern = ".*(" + urlPattern + ").*";
        }
        this.urlPatterns.add(urlPattern);
    }
}
